<?php

$subcategory_url = url_for2('subcategory', array('subcategory' => $subcategory->getId(), 'page' => 1));
$category_url = url_for2('category', array('category' => $subcategory->getSubcategoryCategory()->getId()));
$forum_url = url_for('forum/categories');


echo <<<HTML
<a href="{$forum_url}">Forum</a> >>
<a href="{$category_url}">{$subcategory->getSubcategoryCategory()->getName()}</a> >> 
<a href="{$subcategory_url}">{$subcategory->getName()}</a><br /><br /> 
HTML;
?>

<?php echo $subcategory->getName(); ?>
<br />
<a href="<?php echo url_for2('newtopic', array('subcategory' => $subcategory->getId())); ?>">New topic</a>
<br />

<table class="subcategory">
	<tr>
		<th>Topic</th>
		<th>Créateur</th>
		<th>Dernière réponse</th>
	</tr>
<?php
if ($topics->count() == 0)
{
	echo "<p>Aucun topic</p>";
}
else
{
	foreach ($topics as $topic)
	{
		$topic_url = url_for2('topic', array('topic' => $topic->getId(), 'page' => 1));

		// Y a-t-il des nouveaux messages dans ce topic ?
		$new_messages = true;
		if ($read->offsetExists($topic->getId()))
		{
			$diff = Utils::diff(new DateTime($read->offsetGet($topic->getId())), new DateTime($topic->getLastPostAt()));
			if ($diff == '-')
				$new_messages = false;
		}
		
		$new_messages_text = ($new_messages) ? "[N]" : "[ ]";
			
		echo <<<HTML
		<tr class="topic">
			<td>
				$new_messages_text <a href="{$topic_url}">{$topic->getName()}</a>
			</td>
			<td>
				{$topic->getTopicOwner()->getNickname()}
			</td>
			<td>
				{$topic->getLastPostAt()} par {$topic->getLastPostBy()} 
			</td>
		</tr>
HTML;
	}
}
?>
</table>

<p class="center">
<?php 
echo Utils::pagination($page, $total_topics, $topics_by_page, 'subcategory', array('subcategory' => $subcategory->getId()));
?>
</p>
